package com.study.kafkademo01.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@PropertySource("classpath:/kafka.properties")
public class KafkaConfig {

    private static Logger log = LoggerFactory.getLogger(KafkaConfig.class);

    private static Properties properties = new Properties();

    static {
        try{
            InputStream in = KafkaConfig.class.getClassLoader().getResourceAsStream("kafka.properties");
            properties.load(in);
        }catch (IOException e){
            properties = null;
            log.info("Kafka配置加载失败");
        }
    }

    public static Properties getKafkaProperties(){
        if(properties != null){
            return properties;
        }else{
            try{
                InputStream in = KafkaConfig.class.getClassLoader().getResourceAsStream("kafka.properties");
                properties.load(in);
                return properties;
            }catch (IOException e){
                properties = null;
                log.info("Kafka配置加载失败");
                return properties;
            }
        }
    }
}
